include /eclipse/runtime-EclipseApplication/tank/Makefile_e.common 
export AR=ar
export YACPP=yacc

#export DEFINES_CPP += -DNEWCOORDIN
export DEFINES_CPP += -D__ONLY_STAND_ALONE_MODE__
#=============================Xenomai==============================================
###### USER SPACE BUILD (no change required normally) ######
#ifeq ($(KERNELRELEASE),)
#ifneq ($(APPLICATIONS),)

### Default Xenomai installation path
XENO ?= /usr/xenomai

XENOCONFIG=$(shell PATH=$(XENO):$(XENO)/bin:$(PATH) which xeno-config 2>/dev/null)

CFLAGS +=$(shell $(XENOCONFIG) --xeno-cflags) $(MY_CFLAGS)

CPPFLAGS +=$(shell $(XENOCONFIG) --xeno-cflags) $(MY_CFLAGS) 

LDFLAGS +=$(shell $(XENOCONFIG) --xeno-ldflags) $(MY_LDFLAGS) -lnative -lrtdk

# This includes the library path of given Xenomai into the binary to make life
# easier for beginners if Xenomai's libs are not in any default search path.
export LDFLAGS +=-Xlinker -rpath -Xlinker $(shell $(XENOCONFIG) --libdir) 
#endif
#endif
#=============================Xenomai End==============================================
export MAINDIR=.

export INCLUDES_CPP +=-I$(MAINDIR)

export LDFLAGS += -g$(MAINDIR)

#============================================================================
# Optimized Code - Requires more virtual memory.
export CPPFLAGS += -O3
#============================================================================
# Ignorar warnings:
export CPPFLAGS += -w

# Include information for GDB:
#export CPPFLAGS += -g

export DEFINES_C=

export CFLAGS=
export DEBUGFLAGS=
export LDFLAGS+=-L. -g

.SUFFIXES : .cpp .o .c .y

SIMOBJS=neighval.o	\
macroexp.o		\
evaldeb.o		\
zone.o			\
except.o		\
strutil.o		\
flatcoup.o		\
flatcoor.o		\
randlib.o		\
ntupla.o		\
cellstate.o		\
gram.o			\
undefd.o		\
atomic.o		\
coupled.o		\
model.o			\
modeladm.o		\
msgadm.o		\
msgbag.o		\
real.o			\
realfunc.o		\
realprec.o		\
impresion.o		\
port.o			\
stdaload.o		\
root.o			\
cdTime.o		\
ini.o			\
mainsimu.o      \
process.o		\
procadm.o		\
simulat.o		\
portlist.o		\
coordin.o		\
atomcell.o		\
tdcell.o		\
idcell.o		\
ltranadm.o		\
coupcell.o		\
coorcell.o		\
synnode.o		\
tbool.o			\
parser.o		\
netload.o		\
bsdchann.o		\
flatdcoo.o		\
atomdata.o      \
revatomic.o     \
portadm.o		\
revsimulator.o		


# if we are compiling for Windows 95, comment the last two lines

EXAMPLESOBJS=cdQueue.o main.o generat.o cpu.o transduc.o trafico.o distri.o com.o linpack.o debug.o driver.o Compass1.o Compass2.o Motor1.o Motor2.o Motor3.o MovementController.o RadarController.o Sonar1.o Sonar2.o nxtdriver.o register.o

LIBNAME=simu
LIBS += -lsimu
ALLOBJS=${EXAMPLESOBJS} ${SIMOBJS} 
INIOBJS=initest.o ini.o
ALLSRCS=${ALLOBJS:.o=.cpp} gram.y 

all: libs simu_e makerand toMap toCDPP

libs: libsimu.a 

simu_e: ${EXAMPLESOBJS} libsimu.a $(MODELLIBS) 
	${CPP} ${LDFLAGS} -o $@ ${ALLOBJS} ${LIBS}


initest: ${INIOBJS} 
	${CPP} ${LDFLAGS} -o $@ ${INIOBJS} 

drawlog: drawlog.o libsimu.a
	${CPP} ${LDFLAGS} -o $@ drawlog.o ${LIBS}

makerand: makerand.o libsimu.a
	${CPP} ${LDFLAGS} -o $@ makerand.o ${LIBS}

toMap: toMap.o libsimu.a
	${CPP} ${LDFLAGS} -o $@ toMap.o ${LIBS}

toCDPP: toCDPP.o libsimu.a
	${CPP} ${LDFLAGS} -o $@ toCDPP.o ${LIBS}

randEvent: randEvent.o libsimu.a
	${CPP} ${LDFLAGS} -o $@ randEvent.o ${EXAMPLESOBJS} ${LIBS}

exptest: synnode.o
	${CPP} ${LDFLAGS} -o $@ synnode.o
	
parser: parser.o gram.o
	${CPP} ${LDFLAGS} -o $@ parser.o gram.o

libsimu.a: ${SIMOBJS}
	${AR} crs lib${LIBNAME}.a ${SIMOBJS}

clean:
	- rm -f *.o *.a simu_e core drawlog initest exptest parser makerand toMap toCDPP allinc/* *.exe 
	- rm -r Target

inc:
	cd allinc && rm -rf * && ln -s *.h .

depend:
	makedepend -Y ${ALLSRCS}

backup:
	tar -cvf simu.tar *.cpp *.h *.c *.y makefile* *.ma *.ev *.vpj *.bat *.txt *.val *.inc *.map; gzip simu.tar; mv simu.tar.gz simu.tgz

########################
# Without Optimization
Compass1.o: Compass1.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $< 

Compass2.o: Compass2.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $< 

Motor1.o: Motor1.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $< 

Motor2.o: Motor2.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $< 

Motor3.o: Motor3.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $< 

MovementController.o: MovementController.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $< 

RadarController.o: RadarController.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $< 

Sonar1.o: Sonar1.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $< 

Sonar2.o: Sonar2.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $< 

nxtdriver.o: nxtdriver.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $< 

register.o: register.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $< 


generat.o: generat.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

cdQueue.o: cdQueue.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

cpu.o: cpu.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

transduc.o: transduc.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

trafico.o: trafico.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

msgadm.o: msgadm.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

portadm.o: portadm.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

root.o: root.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

driver.o: driver.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

parser.o: parser.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

main.o: main.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

drawlog.o: drawlog.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

toMap.o: toMap.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

toCDPP.o: toCDPP.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

makerand.o: makerand.cpp
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

mainsimu.o: mainsimu.cpp 
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<

# Uncomment these lines only for Windows
#macroexp.o: macroexp.cpp
#	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<
#
#flatcoup.o: flatcoup.cpp
#	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} $<
########################

.cpp.o:
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} ${OPTCPPFLAGS} $<

.c.o:
	${CC} -c ${INCLUDES_C} ${DEFINES_C}  ${DEBUGFLAGS} ${CFLAGS} ${OPTCPPFLAGS} $<

.y.o:
	bison -d -v -o gram.c gram.y
	${CPP} -c ${INCLUDES_CPP} ${DEFINES_CPP} ${DEBUGFLAGS} ${CPPFLAGS} ${OPTCPPFLAGS} ${@:.o=.c} 
	rm $*.c
	
# DO NOT DELETE

gram.o: synnode.h parser.h ntupla.h
driver.o: driver.h
